/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Random;

/**
 * <p>Project: jse2303 - ImageIODemo
 * <p>Powered by webrx On 2023-07-24 17:05:50
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ImageIODemo {
    public static void main(String[] args) throws Exception {
        //建立一图片
        int width = 800;
        int height = 800;
        BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Random rand = new Random();
        Graphics2D g = img.createGraphics();
        //设置线条和文件的，抗锯齿（平滑）
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);


        //椭圆 正
        g.setColor(new Color(232, 16, 153, 216));
        //g.fillOval(150, 150, 200, 200);

        g.drawOval(150, 150, 200, 200);

        g.fillRect(50, 50, 50, 50);


        //for (int i = 0; i < 10; i++) {
        //    g.setColor(new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256), rand.nextInt(30) + 20));
        //
        //    g.setStroke(new BasicStroke(rand.nextInt(1, 9)));
        //    int x1 = rand.nextInt(width);
        //    int y1 = rand.nextInt(height);
        //    int x2 = rand.nextInt(width);
        //    int y2 = rand.nextInt(height);
        //    g.drawLine(x1, y1, x2, y2);
        //
        //}


        //String letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        //g.setColor(Color.RED);
        //Random rand = new Random();
        //for (int i = 0; i < 1030; i++) {
        //    g.setColor(new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
        //    Font font = new Font("宋体", Font.BOLD, rand.nextInt(12, 50));
        //    g.setFont(font);
        //    int pos = rand.nextInt(letter.length());
        //    String s = letter.substring(pos, pos + 1);
        //    int x = rand.nextInt(0, width);
        //    int y = rand.nextInt(0, height);
        //    g.drawString(s, x, y);
        //}

        g.dispose();

        //输出图像
        ImageIO.write(img, "png", new File("check01.png"));
    }
}
